package Dao.impl;/*
 *86180
 *2021/10/2
 *18:37
 */

import Dao.UserDao;
import entity.User;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import util.DruidUtil;

import java.sql.SQLException;

public class UserDaoImpl implements UserDao {
    private QueryRunner queryRunner=new QueryRunner();
    @Override
    public User select(String username) {
        try {
            return queryRunner.query(DruidUtil.getConnection(), "select * from user where username=?;",new BeanHandler<>(User.class),username);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage()+"用户名查询异常");
        }
    }

    @Override
    public int update(String username, String newpassword) {
        try {
            return queryRunner.update(DruidUtil.getConnection(), "update user set password=? where username=?;",newpassword,username);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage()+"修改用户密码异常");
        }
    }
}
